﻿@{
    Layout = "~/Views/Shared/_level2.cshtml";
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
    }
}
<title>系统管理-企业信息</title>
<link href="/SiteUI/Admin/share.css" rel="stylesheet" />
<link href="/SiteUI/Admin/Company.css" rel="stylesheet" />
@section contentnavi{
    <div id="appTitle">
        系统管理
    </div>
<ul id="slideNavi">
    <li><a class="Lite" href="/Admin/Company"><i class="icon-qiyerenzheng"></i>企业信息<i class="icon-navigatenext arrow-go"></i></a></li>
    <li><a class="Lite" href="/Admin/Organize"><i class="icon-wangluo1"></i>组织架构<i class="icon-navigatenext arrow-go"></i></a></li>
    <li><a class="Lite" href="/Admin/Accounts"><i class="icon-accountbox"></i>员工账号<i class="icon-navigatenext arrow-go"></i></a></li>
    <li><a class="Lite" href="/Admin/Authority"><i class="icon-security"></i>权限设置<i class="icon-navigatenext arrow-go"></i></a></li>
    <li><a class="Lite" href="/Admin/OpenApi"><i class="icon-swaphoriz"></i>开放接口<i class="icon-navigatenext arrow-go"></i></a></li>
    <li><a class="Lite" href="/Admin/Portal"><i class="icon-034library"></i>企业门户<i class="icon-navigatenext arrow-go"></i></a></li>
    <li><a class="Lite" href="/Admin/CloudApp"><i class="icon-nowwidgets"></i>应用管理<i class="icon-navigatenext arrow-go"></i></a></li>
</ul>
}

<div class="col-lg-10 col-lg-offset-1">
    <div class="row InfoBlock">
        <div class="col-lg-12 ib-body" id="ci-name">
            <h4>当前公司名称</h4>
            <div class="button" id="btnSlcCompany">切换公司</div>
        </div>
    </div>
    <!--基本信息-->
    <div class="row InfoBlock">
        <div class="col-lg-12 ib_head">
            <span class="ib_head_title">基本信息</span>
        </div>
        <div class="col-lg-12 ib-body">
            <div class="row info-field">
                <div class="col-lg-2 col-lg-offset-1 if-title">公司Logo</div>
                <div class="col-lg-4 if-value">
                    <img id="ci-logo" src="#" />
                    <a class="LinkTo" id="btnUploadLogo">上传Logo照片</a>
                </div>
                <div class="col-lg-5 if-tip">

                </div>
            </div>
            <div class="row info-field">
                <div class="col-lg-2 col-lg-offset-1 if-title">注册地址</div>
                <div class="col-lg-4 if-value" id="ci-address">
                    <input />
                </div>
                <div class="col-lg-5 if-tip" id="ifm-address">

                </div>
            </div>
            <div class="row info-field">
                <div class="col-lg-2 col-lg-offset-1 if-title">联系电话</div>
                <div class="col-lg-4 if-value" id="ci-phone">
                    <input />
                </div>
                <div class="col-lg-5 if-tip" id="ifm-phone">

                </div>
            </div>
            <div class="row info-field">
                <div class="col-lg-2 col-lg-offset-1 if-title">行业类型</div>
                <div class="col-lg-4 if-value" id="ci-industry">
                    <input />
                </div>
                <div class="col-lg-5 if-tip" id="ifm-industry">

                </div>
            </div>
            <div class="row info-field">
                <div class="col-lg-2 col-lg-offset-1 if-title">企业官网(选填)</div>
                <div class="col-lg-4 if-value" id="ci-website">
                    <input />
                </div>
                <div class="col-lg-5 if-tip" id="ifm-website">

                </div>
            </div>
            <div class="button " id="btnSaveInfo">
                保存修改
            </div>
        </div>
    </div>
    <!--实名认证信息-->
    <div class="row InfoBlock">
        <div class="col-lg-12 ib_head">
            <span class="ib_head_title">企业实名认证</span>
            <div class="row sectionTip">
                <div class="TLCertify ct-logo">天联认证</div>
                <br />
                天联认证服务是为了保证平台用户利益的重要措施之一，其目的是为了保证平台上的企业都是真实存在的组织团体。
                认证通过的企业，在对应企业名称旁会显示显著标识，能显著增加自身的信誉。
            </div>
        </div>
        <div class="col-lg-12 ib-body">
            <div class="row info-field">
                <div class="col-lg-2 col-lg-offset-1 if-title">组织机构代码</div>
                <div class="col-lg-4 if-value" id="ci-ogrcode">

                </div>
                <div class="col-lg-5 if-tip">

                </div>
            </div>
            <div class="row info-field">
                <div class="col-lg-2 col-lg-offset-1 if-title">工商执照注册号</div>
                <div class="col-lg-4 if-value" id="ci-bizlicence">

                </div>
                <div class="col-lg-5 if-tip">

                </div>
            </div>
            <div class="row info-field">
                <div class="col-lg-2 col-lg-offset-1 if-title">营业执照照片</div>
                <div class="col-lg-4 if-value">
                    <img id="ci-bizlicencepic" />
                    <a id="seeLicense" class="LinkTo" href="" target="_blank">查看原图</a>
                </div>
                <div class="col-lg-5 if-tip">

                </div>
            </div>
        </div>
        <div class="col-lg-6 col-lg-offset-3 certification" id="in-certification">
            <h5>您的公司认证资料正在审核中</h5>
            <span>提交人：</span><span class="Submitter"></span>
            <br />
            <span>提交时间：</span><span class="CommitTime"></span>
        </div>
        <div class="col-lg-6 col-lg-offset-3 certification" id="ok-certification">
            <h5>您的公司认证资料已通过审核</h5>
            <span>有效期至：</span><span class="ValidityPeriod"></span>
            <br />
            <span>提交人：</span><span class="Submitter"></span>
            <br />
            <span>提交时间：</span><span class="CommitTime"></span>
        </div>
        <div class="col-lg-6 col-lg-offset-3 certification" id="unpass-certification">
            <h5>您的公司认证资料未能通过审核</h5>
            <span>原因：</span><span class="FailureCause"></span>
            <br />
            <span>提交人：</span><span class="Submitter"></span>
            <br />
            <span>提交时间：</span><span class="CommitTime"></span>
            <a class="LinkTo" href="/Company/NewCompany">重新认证</a>
        </div>
        <div class="col-lg-6 col-lg-offset-3 certification" id="expired-certification">
            <h5>您的公司认证资料已过期</h5>
            <span>有效期至：</span><span class="ValidityPeriod"></span>
            <br />
            <span>提交人：</span><span class="Submitter"></span>
            <br />
            <span>提交时间：</span><span class="CommitTime"></span>
            <a class="LinkTo" href="/Company/NewCompany">重新认证</a>
        </div>
    </div>
    <br />
</div>

<script>
    DataBinding={
       Company: {
       },
       PhoneFormat: /(^1[3,4,5,7,8]{1}[0-9]{9}$)|(^\d{4}-\d{7,8}$)/,  //手机号格式验证的正则
       UploadLogo: null,
       companyInformation: function () {
           var cmpny = $.Cookie("admin-currentcompany");
           var cid = ObjHelper.IsEmpty(cmpny) ? -1:cmpny.idstr;
           $.getJSON("/Admin/GetCompanyInformation", { companyid: cid }, function (rtn) {
                if (rtn.IsPositive) {
                    DataBinding.Company = rtn.Data;
                    $("#ci-name >h4").vl(DataBinding.Company.name);
                    $("#ci-logo").attr("src", "" + DataBinding.Company.logourl + "");
                    $("#ci-address>input").vl(DataBinding.Company.address);
                    $("#ci-phone>input").vl(DataBinding.Company.officephone);
                    $("#ci-industry>input").vl(DataBinding.Company.industry);
                    $("#ci-website>input").vl(DataBinding.Company.website);
                    $("#ci-ogrcode").vl(DataBinding.Company.bizorgcode);
                    $("#ci-bizlicence").vl(DataBinding.Company.licencecode);
                    $("#ci-bizlicencepic").attr("src", DataBinding.Company.bizlicencepic);
                    $("#seeLicense").attr("href", DataBinding.Company.bizlicencepic);

             		$(".Submitter").vl(DataBinding.Company.submitter_realname|| DataBinding.Company.submitter);
             		$(".CommitTime").vl(DataBinding.Company.createtime);
                    $(".Submitter").vl(DataBinding.Company.submitter_realname || DataBinding.Company.submitter);
                    var d = new Date(DataBinding.Company.createtime).format("yyyy/MM/dd hh:mm:ss");
             		$(".CommitTime").vl(d);
             		//$(".ValidityPeriod").vl(DataBinding.Company.validityPeriod);
             		$(".FailureCause").vl(DataBinding.Company.feedback);
             			switch ( DataBinding.Company.status) {
                            case "Pending": //审核中
                                DataBinding.CertificationVerify();
                                break;
                            case "Aborted": //审核不通过
                               DataBinding.againCertification();
                                break;
                            case "Completed":  //审核通过
                                DataBinding.CertificationSuccess();
                                break;
                            //已过期
                       }
                } else {
                    error("加载失败","没有与您相关的公司，请创建或申请加入某个公司");
                }
            });
        },
       onUploadLogoChange: function (ev) {
            switch (ev.Status) {
                case "imageLoaded":
                    $("#ci-logo").attr("src", ev.Item.thumbnail);
                    break;
                case "uploadEnd":
                    DataBinding.Company.logourl = ev.Item.Result.path;
                    $.getJSON("/Admin/UpdateCompanyInfo", DataBinding.Company, function(rtn){
                    	   if (rtn.IsPositive) {
                    	   	  success("成功","上传企业LOGO成功");
                    	   }
                    	   else{
                    	      error("失败","请检查图片格式后再试");
                    	   }
                    });
                    break;
            }
       },
       checkAddress:function(){
         var address = $("#ci-address>input").vl();
            if (!address.length > 0) {
                $("#ifm-address").vl("请填写正确的注册地址");
                return false;
            } else {
                $("#ifm-address").vl("");
                return true;
            }
        },
       checkPhone:function(){
           var phone = $("#ci-phone>input").vl();
         if (!DataBinding.PhoneFormat.test(phone)) {
                $("#ifm-phone").vl("请填写正确的联系电话");
                return false;
            } else {
                $("#ifm-phone").vl("");
                return true;
            }
       },
       checkIndustry:function(){
           var address = $("#ci-industry>input").vl();
           if (!address.length > 0) {
               $("#ifm-industry").vl("请填写正确的行业类型");
               return false;
           } else {
               $("#ifm-industry").vl("");
               return true;
           }
       },
       CertificationVerify:function(){
        	 $("#in-certification").show();
        },
       againCertification:function(){
        	 $("#unpass-certification").show();
        },
       CertificationSuccess:function(){
        	 $("#ok-certification").show();
        },
       onSaveInfoChange: function () {
           if (DataBinding.checkAddress() && DataBinding.checkPhone() && DataBinding.checkIndustry()) {
                DataBinding.Company.address = $("#ci-address>input").vl();
                DataBinding.Company.officephone = $("#ci-phone>input").vl();
                DataBinding.Company.industry = $("#ci-industry>input").vl();
                var website =  $("#ci-website>input").vl();
                if (website.length > 0 && website.substring(0, 7) != "http://") {
                    DataBinding.Company.website = "http://" + website;
                } else {
                    DataBinding.Company.website = website;
                }
                $.post("/Admin/UpdateCompanyInfo", DataBinding.Company, function (rtn) {
                    if (rtn.IsPositive) {
                        success("成功","企业资料已保存");
                    }
                    else{
                        error("失败","保存失败，请稍后重试");
                    }
                })
            }
        }
    }

    $(function () {
        var navis = $("#slideNavi>li>a");
        for (var i = 0; i < navis.length; i++) {
            if (navis.eq(i).attr("href") == window.location.pathname) {
                navis.eq(i).addClass("current");
                break;
            }
        }

        //获得公司信息
        DataBinding.companyInformation();
        DataBinding.UploadLogo = new LiberUI.Uploader("#btnUploadLogo")
                                         .option("FileType", "image/*")
                                         .option("MaxSize", 10240000)
                                         .update();
        DataBinding.UploadLogo.on("change", DataBinding.onUploadLogoChange);
        $("#ci-address>input").blur( DataBinding.checkAddress);
        $("#ci-phone>input").blur( DataBinding.checkPhone);
        $("#ci-industry>input").blur(DataBinding.checkIndustry);
        $("#btnSaveInfo").on("click", DataBinding.onSaveInfoChange);

    })
</script>